package com.huajin.iot.monitor.controller;

import com.fasterxml.jackson.databind.JsonNode;
import com.huajin.iot.common.utils.PageUtils;
import com.huajin.iot.common.utils.Query;
import com.huajin.iot.common.utils.R;
import com.huajin.iot.monitor.domin.GatewayDO;
import com.huajin.iot.monitor.service.GatewayService;
import com.huajin.iot.monitor.service.impl.EsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 网关设备
 *
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2018-10-10 17:17:46
 */
@Api(tags = {"告警获取接口"})
@RestController
@RequestMapping("/system/warn")
public class WARNController {
    @Autowired
    private GatewayService gatewayService;

    @Autowired
    private EsServiceImpl esServiceImpl;

    @ApiOperation("获取小时告警统计")
    @GetMapping("/get24HourCount")
    //@RequiresPermissions("system:gateway:gateway")
    public R get24HourCount() {
        return R.ok(esServiceImpl.get24HourCount());
    }


    @ApiOperation("获取星期告警统计")
    @ResponseBody
    @GetMapping("/get1WeekCount")
    //@RequiresPermissions("system:gateway:gateway")
    public R get1WeekCount() {
        return R.ok(esServiceImpl.get1WeekCount());
    }


    @ApiOperation("获取月份告警统计")
    @ResponseBody
    @GetMapping("/get12MonthCount")
   // @RequiresPermissions("system:gateway:gateway")
    public R get12MonthCount() {
        return R.ok(esServiceImpl.get12MonthCount());
    }



    @ApiOperation(" 获取告警事件列表")
    @ResponseBody
    @GetMapping("/get30MinWarnList")
    //@RequiresPermissions("system:warn:warn")
    public R get30MinWarnList() {
        return R.ok(esServiceImpl.get30MinWarnList());
    }


    @ApiOperation("获取设备类型告警统计*")
    @ResponseBody
    @GetMapping("/getWarnByAsset")
    //@RequiresPermissions("system:warn:warn")
    public R getWarnByAsset() {
        return R.ok(esServiceImpl.getWarnByAsset());
    }


    @ApiOperation(" 获取地域告警统计")
    @ResponseBody
    @GetMapping("/getWarnByArea")
    //@RequiresPermissions("system:warn:warn")
    public R getWarnByArea() {
        return R.ok(esServiceImpl.getWarnByArea());
    }


    @ApiOperation(" 获取网关IP 和 网关资产信息")
    @ResponseBody
    @GetMapping("/getGateWayIP")
    //@RequiresPermissions("system:warn:warn")
    public R getGateWayIP() {
        return R.ok(esServiceImpl.getGateWayIP());
    }
//
//
//    /**
//     * 修改
//     */
//    @ApiOperation("更新网关设备信息")
//    @ResponseBody
//    @PostMapping("/update")
//    @RequiresPermissions("system:gateway:edit")
//    public R update(GatewayDO gateway) {
//        if (gatewayService.update(gateway) > 0) {
//            return R.ok();
//        } else {
//            return R.error(1, "更新失败");
//        }
//    }
//
//    /**
//     * 删除
//     */
//    @ApiOperation("删除网关")
//    @PostMapping("/remove")
//    @ResponseBody
//    @RequiresPermissions("system:gateway:remove")
//    public R remove(Long id) {
//        if (gatewayService.remove(id) > 0) {
//            return R.ok();
//        }
//        return R.error(1, "删除失败");
//    }
//
//    /**
//     * 删除
//     */
//    @ApiOperation("批量删除网关")
//    @PostMapping("/batchRemove")
//    @ResponseBody
//    @RequiresPermissions("system:gateway:batchRemove")
//    public R remove(@RequestParam("ids[]") Long[] ids) {
//        if (gatewayService.batchRemove(ids) == ids.length) {
//            return R.ok();
//        } else {
//            return R.error(1, "删除失败");
//        }
//    }
}
